package edu.java.lectures.lec03.design.patterns;

// class which has ONLY ONE instance/object
// Singleton -> is ANTI-pattern

public class SingletonExample {

    // step 1 - hidden/private static instance of the class
    private static SingletonExample instance = null;

    // step 2 - constructor with RESTRICTED ACCESS MODIFIER
    // could be protected
    private SingletonExample() {
    }

    // step 3 - STATIC method for access to the SINGLE/ONLY instance of the
    // class
    public static SingletonExample getInstance() {
	// step 4 - lazy loading
	// lazy loading (used for "large/heavy" objects)
	if (instance == null) {
	    instance = new SingletonExample();
	}
	return instance;
    }

    public static void main(String[] args) {
	// step 5 - usage
	SingletonExample.getInstance().test();
    }

    // follow dynamic methods (i.e. NOT STATIC)

    public String test() {
	return "test";
    }

    // public static void main(String[] args) {
    // Singleton.getInstance().test();
    // }
}

// class SingletonTestCase extends Singleton{
//
// private static Singleton instance;
//    
//    
// public String test() {
// return "alabala";
// }
// }